import TencentCloudChat, { Message } from '@tencentcloud/chat'

export const TencentMessageTransform = (message: Message) => {
  if (message.type === TencentCloudChat.TYPES.MSG_TEXT) {
    // 文本消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.TextPayload
    return message.payload.text
  } else if (message.type === TencentCloudChat.TYPES.MSG_IMAGE) {
    // 图片消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.ImagePayload
    return message.payload.imageInfoArray.url
  } else if (message.type === TencentCloudChat.TYPES.MSG_AUDIO) {
    // 音频消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.AudioPayload
    return message.payload.url
  } else if (message.type === TencentCloudChat.TYPES.MSG_VIDEO) {
    // 视频消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.VideoPayload
    return message.payload.videoUrl
  } else if (message.type === TencentCloudChat.TYPES.MSG_FILE) {
    // 文件消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.FilePayload
    return message.payload.fileUrl
  } else if (message.type === TencentCloudChat.TYPES.MSG_CUSTOM) {
    // 自定义消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.CustomPayload
    return message.payload.description
  } else if (message.type === TencentCloudChat.TYPES.MSG_MERGER) {
    // 合并消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.MergerPayload
    return message.payload.title
  } else if (message.type === TencentCloudChat.TYPES.MSG_LOCATION) {
    // 地理位置消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.LocationPayload
    return message.payload.description
  } else if (message.type === TencentCloudChat.TYPES.MSG_GRP_TIP) {
    // 群提示消息 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.GroupTipPayload
    return message.payload
  } else if (message.type === TencentCloudChat.TYPES.MSG_GRP_SYS_NOTICE) {
    // 群系统通知 - https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html#.GroupSystemNoticePayload
    // const { operationType, userDefinedField } = message.payload;
    // operationType - 操作类型
    // userDefinedField - 用户自定义字段（对应 operationType 为 255）
    // 使用 RestAPI 在群组中发送系统通知时，接入侧可从 userDefinedField 拿到自定义通知的内容。
    return message.payload
  }
}
